package com.baizhi.service.impl;

import com.baizhi.dao.PatientDao;
import com.baizhi.entity.Patient;
import com.baizhi.service.PatientService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientServiceImpl implements PatientService {
    private PatientDao patientDao;
    @Autowired
    public void setPatientDao(PatientDao patientDao) {
        this.patientDao = patientDao;
    }

    @Override
    public void insertPatient(Patient p) {
        patientDao.insertPatient(p);
    }

    @Override
    public void deletePatient(Integer pid) {
        patientDao.deletePatient(pid);
    }

    @Override
    public Patient selectById(Integer id) {
        Patient patient = patientDao.selectById(id);
        return patient;
    }

    @Override
    public void updatePatient(Patient p) {
        patientDao.updatePatient(p);
    }

    @Override
    public PageInfo<Patient> selectByPage(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Patient> patients = patientDao.selectAll(name);
        PageInfo<Patient> pageInfo = new PageInfo<>(patients);
        return pageInfo;
    }
}
